Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add nixpkgs_cc_configure() #40

Merged
merged 3 commits into from
Nov 13, 2018
Merged

Add nixpkgs_cc_configure() #40

merged 3 commits into from
Nov 13, 2018

Conversation

mboes
Copy link
Member

@mboes mboes commented Nov 10, 2018

A call to this macro in your WORKSPACE file is a simple one-liner. It
declares a nixpkgs_package with all the tools we need for a CC
toolchain, and then gets Bazel to use them. Making sure the Bazel uses
the C compiler from Nixpkgs rather than whatever it autodetects on the
PATH improves build hermeticity, and side steps a whole host of issues
we've been facing on rules_haskell due to system GCC wanting to link
against the system GLIBC while Nixpkgs GCC wants another one.

@mboes mboes force-pushed the cc-configure-with-nix branch from 45386ad to 2582aa2 Compare November 11, 2018 00:09
@mboes
Copy link
Member Author

mboes commented Nov 11, 2018

This is #16 reopened.

Copy link
Member

@mrkkrp mrkkrp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, although I forgot almost all context by now. So what happened to the previous best practice of just running everything in a nix shell? Why the PR has been resurrected?

Copy link
Contributor

@Profpatsch Profpatsch left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good in principle, a few comments.
There’s the question whether we want to support both repository and repositories indefinitely. We now have two rules which allow both, plus two different ways to check for consistency (see comment below). I’m going to open a separate issue for that.

@mboes if you don’t have time, I can implement my suggested changes.

Meta comment: Does this mean we are going to need to implement wrappers like this for each language Google supports officially?

use.
"""
if repository and repositories or not repository and not repositories:
fail("Specify one of repository or repositories (but not both).")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have this logic in both nixpkgs_package and here. Actually, nixpkgs_package silently overwrites repository if repositories has a "nixpkgs" field, which is a bug. Should be factored out.

tool: repository_ctx.path(Label("@nixpkgs_cc_toolchain//:bin/" + tool))
for tool in res.stdout.splitlines()
}
cc_autoconf_impl(repository_ctx, overriden_tools = overriden_tools)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

    elif cpu_value == "x64_windows":
        # TODO(ibiryukov): overriden_tools are only supported in configure_unix_toolchain.
        # We might want to add that to Windows too(at least for msys toolchain).
        configure_windows_toolchain(repository_ctx)

https://github.com/bazelbuild/bazel/blob/master/tools/cpp/cc_configure.bzl#L48

Something to keep in mind.

tool: repository_ctx.path(Label("@nixpkgs_cc_toolchain//:bin/" + tool))
for tool in res.stdout.splitlines()
}
cc_autoconf_impl(repository_ctx, overriden_tools = overriden_tools)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The rule uses repository_ctx.which in unix_cc_configure.bzl to resolve paths passed through overridden_tools, and it’s not clear from the documentation what that means for the absolute paths we pass it: bazelbuild/bazel#6660 (I’m too lazy to look into the Java source right now, but I assume it returns absolute paths unmodified).

Copy link
Contributor

@thufschmitt thufschmitt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@mboes
Copy link
Member Author

mboes commented Nov 13, 2018

There’s the question whether we want to support both repository and repositories indefinitely.

I think we should. Setting only nixpkgs= is such a common case that I think we should have a special case for it.

mboes and others added 2 commits November 13, 2018 14:38
This refactor has two simple goals:

* Simplify control flow: callers no longer need to `if-then-else`
  themselves, which becomes cumbersome when you have a sequence of
  calls to `repository_ctx.execute()`.
* Improve the output on failure (by listing the failing command).
@mboes mboes force-pushed the cc-configure-with-nix branch 2 times, most recently from 167e095 to 27b176f Compare November 13, 2018 14:16
@mboes
Copy link
Member Author

mboes commented Nov 13, 2018

@Profpatsch PTAL

This macro calls cc_autoconf_impl like before, but ahead of then also
defines a nixpkgs_package with all the tools we want for the CC
toolchain.
@mboes mboes force-pushed the cc-configure-with-nix branch from 27b176f to 200bff4 Compare November 13, 2018 14:22
@mboes
Copy link
Member Author

mboes commented Nov 13, 2018

Meta comment: Does this mean we are going to need to implement wrappers like this for each language Google supports officially?

Yes.

@mboes mboes merged commit 65d6dd1 into master Nov 13, 2018
@mboes mboes deleted the cc-configure-with-nix branch November 13, 2018 18:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants